/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2023-12-20 23:12:19
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-01-08 09:52:41
 * @FilePath: /tuberculosis_screening_display_system/src/api/global.api.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { http, METHOD } from "@/utils/request";
import { AxiosResponse } from "axios";

export function getAreaSchedule() {
  return http
    .request({
      url: "/api/area-schedule",
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data.data);
}

export function getRegionSchedule() {
  return http
    .request({
      url: "/api/region-schedule",
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data.data)
    .then((data) =>
      data.map((item) => {
        const rate = Number(((item.num / item.count) * 100).toFixed(2));
        return { ...item, rate: rate > 100 ? 100 : rate };
      })
    );
}

export function getSchedule() {
  return http
    .request({
      url: "/api/schedule",
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data.data)
    .then((data) =>
      data.map((item) => {
        const rate = Number(((item.num / item.count) * 100).toFixed(2));
        return { ...item, rate: rate > 100 ? 100 : rate };
      })
    );
}

export function getFlow() {
  return http
    .request({
      url: "/api/flow",
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data.data);
}

export function getTypes() {
  return http
    .request({
      url: "/api/types",
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data.data);
}

export function getMonths() {
  return http
    .request({
      url: "/api/months",
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data.data);
}

export function getGeoJson(code: number, isFull: boolean = true) {
  const params = isFull ? `${code}_full` : code;
  return http
    .request({
      url: `https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=${params}`,
      method: METHOD.GET,
    })
    .then((res: AxiosResponse) => res.data);
}
